package io.github.jesse205.dragdrop.pro.manager

import android.content.Context
import android.util.Log
import io.github.jesse205.dragdrop.pro.R
import io.github.jesse205.dragdrop.pro.app.AppPreference
import io.github.jesse205.dragdrop.pro.app.AppPreference.ThemeType.MATERIAL2
import io.github.jesse205.dragdrop.pro.app.AppPreference.ThemeType.MATERIAL3
import io.github.jesse205.dragdrop.pro.extensions.thisApp

class ThemeManager(val context: Context) {

    private var themeType: AppPreference.ThemeType? = null
    private val preferenceThemeType get() = context.thisApp.appPreference.themeType

    fun applyTheme() {
        applyTheme(preferenceThemeType)
    }

    private fun applyTheme(themeType: AppPreference.ThemeType) {
        this.themeType = themeType
        val themeId: Int = when (themeType) {
            MATERIAL2 -> R.style.Theme_DragAndDropTransferStationPro_Material2
            MATERIAL3 -> R.style.Theme_DragAndDropTransferStationPro_Material3
        }
        context.setTheme(themeId)
    }

    fun isThemeChanged(): Boolean {
        return isThemeChanged(preferenceThemeType)
    }

    fun isThemeChanged(themeType: AppPreference.ThemeType): Boolean {
        return (themeType != this.themeType).also {
            Log.i(TAG, "isThemeChanged: $it")
        }
    }

    companion object {
        private const val TAG = "ThemeManager"
    }

}